﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TSites.Config;
using TSites.Language;
using TSites.MasterCode;
using TSites.Login.User;

namespace TSites.Utils
{
    public class TsUtils
    {
        #region Member Variables

        private static TsUtils _instance;

        #endregion
        
        #region Constructors

        private TsUtils() { }//constructor

        #endregion

        #region Function

        /// <summary>
        /// Get instance
        /// </summary>
        /// <returns>TsUtils</returns>
        public static TsUtils GetInstance()
        {
            if (_instance == null)
                _instance = new TsUtils();
            return _instance;
        }

        public String GetResourceName(String keyValue)
        {
            TsUserInfo userInfo = TsUserInfo.GetLoginUser();
            string langType = null;
            if (userInfo != null)
            {
                langType = userInfo.Language;
            }
            return TsLanguage.GetInstance().GetValue(keyValue, langType);
        }

        public String GetMessage(string messageId, string[] parameters=null)
        {
            TsUserInfo userInfo = TsUserInfo.GetLoginUser();
            string langType = null;
            if (userInfo != null)
            {
                langType = userInfo.Language;
            }
            return TsMessageUtil.GetInstance().GetMessage(messageId, parameters, langType);
        }

        public String GetMasterCode(String keyValue)
        {
            return TsMasterCode.GetInstance(TsConfig.GetInstance().MasterCodeFile).GetValue(keyValue);
        }

        #endregion
        
    }
}